package com.coda.controller;

import com.coda.entity.PaymentType;
import com.coda.result.Result;
import com.coda.service.PaymentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/payment")
@RestController
@Api(tags = "支付方式管理")
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;


    /**
     * 查看所有支付方式
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看所有支付方式")
    public Result<List<PaymentType>> listPaymentType(){
        List<PaymentType> paymentTypes = paymentTypeService.paymentList();
        return Result.ok(paymentTypes);
    }
    /**
     * 保存或更新支付方式
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新支付方式")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }
    /**
     * 根据id删除支付方式
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除支付方式")
    public Result deleteById(Long id){
        paymentTypeService.deleteById(id);
        return Result.ok();

    }

}
